<?php

use think\migration\Migrator;
use think\migration\db\Column;

class CreateUserMediaRecordsTable extends Migrator
{
    /**
     * Change Method.
     *
     * Write your reversible migrations using this method.
     *
     * More information on writing migrations is available here:
     * http://docs.phinx.org/en/latest/migrations.html#the-abstractmigration-class
     *
     * The following commands can be used in this method and Phinx will
     * automatically reverse them when rolling back:
     *
     *    createTable
     *    renameTable
     *    addColumn
     *    renameColumn
     *    addIndex
     *    addForeignKey
     *
     * Remember to call "create()" or "update()" and NOT "save()" when working
     * with the Table class.
     */
    public function change()
    {
        $table = $this->table('user_media_records', ['engine' => 'InnoDB', 'collation' => 'utf8mb4_general_ci', 'comment' => '用户媒体记录表']);
        $table
            ->addColumn('user_id', 'integer', ['signed' => false, 'null' => false, 'comment' => '用户ID'])
            ->addColumn('media_type', 'enum', ['values' => ['IMAGE', 'VIDEO'], 'null' => false, 'comment' => '媒体类型：图片/视频'])
            ->addColumn('media_url', 'string', ['limit' => 255, 'null' => false, 'comment' => '媒体文件URL'])
            ->addColumn('media_size', 'biginteger', ['signed' => false, 'null' => true, 'comment' => '文件大小(字节)'])
            ->addColumn('media_format', 'string', ['limit' => 20, 'null' => true, 'comment' => '文件格式'])
            ->addColumn('width', 'integer', ['signed' => false, 'null' => true, 'comment' => '媒体宽度(像素)'])
            ->addColumn('height', 'integer', ['signed' => false, 'null' => true, 'comment' => '媒体高度(像素)'])
            ->addColumn('duration', 'integer', ['signed' => false, 'null' => true, 'comment' => '视频时长(秒)，仅视频类型有效'])
            ->addColumn('thumbnail_url', 'string', ['limit' => 255, 'null' => true, 'comment' => '缩略图URL'])
            ->addColumn('thumbnail_width', 'integer', ['signed' => false, 'null' => true, 'comment' => '缩略图宽度(像素)'])
            ->addColumn('thumbnail_height', 'integer', ['signed' => false, 'null' => true, 'comment' => '缩略图高度(像素)'])
            ->addColumn('description', 'text', ['null' => true, 'comment' => '描述信息'])
            ->addColumn('status', 'boolean', ['signed' => false, 'default' => 1, 'comment' => '状态：0-已删除 1-正常'])
            ->addColumn('create_time', 'timestamp', ['null' => false, 'default' => 'CURRENT_TIMESTAMP', 'comment' => '创建时间'])
            ->addColumn('update_time', 'timestamp', ['null' => false, 'default' => 'CURRENT_TIMESTAMP', 'update' => 'CURRENT_TIMESTAMP', 'comment' => '更新时间'])
            ->addIndex(['user_id'], ['name' => 'idx_user_id'])
            ->addIndex(['media_type'], ['name' => 'idx_media_type'])
            ->addIndex(['create_time'], ['name' => 'idx_create_time'])
            ->create();
    }
}
